import * as echarts from 'echarts/core';
import {
  GridComponent
} from 'echarts/components';
import {
  BarChart
} from 'echarts/charts';
import {
  CanvasRenderer
} from 'echarts/renderers';
echarts.use([GridComponent, BarChart, CanvasRenderer]);
export default (container) => {
  const myChart = echarts.init(container)
  const option = {
    title:{
      text: '抽取单位数量'
    },

    xAxis: {
      type: 'category',
      data: []
    },
    yAxis: {
      type: 'value'
    },
    series: [
      {
        name:'数量',
        data: [],
        type: 'bar',
        barWidth:'25%'
      }
    ],
    tooltip: {},
  };

  const draw = (config = option) => {
    config && myChart.setOption(config)
  }
  // 监听
  const onClick = (listenParams) => {
    const {eventName, nodeType, clickCallback} = listenParams
    myChart.on(eventName, nodeType, (a) => {
      clickCallback(a)
    })
  }
  return { myChart, option, draw,onClick }
}
